<% content_for :adminpage do %>
    #top-menu {display: none}
    #nav {display: none}
    #right-header {display: none}
    #weasel-coffee {display: none}
<% end %>
<% content_for :admin do %>
    <div id="feedback-menu">
      <ul>
        <li>
          <a href="/admin">Trang Chủ</a>
        </li>
        <li>
          <a>Phân Loại</a>
          <ul>
            <li>
              <a href="/admin/feedback_management?status=nothandle">Chưa Xử Lý</a>
            </li>
            <li>
              <a href="/admin/feedback_management?status=handled">Đã Xử Lý</a>
            </li>
          </ul>
        </li>
      </ul>
    </div>
    <div class='datagrid'>
      <table>
        <tr>
          <th width="2%"><label><input type="checkbox" id="check-all-feedback"/></label></th>
          <th width="20%">Email</th>
          <th width="40%">Nội dung</th>
          <th width="20%">Ngày gửi</th>
          <th width="10%">
            <form id="delete-form" action="/admin/delete_feedback" method="post">
              <% if @status == 'nothandle' %>
                  <button id="delete-all-feedback">Xóa Tất Cả</button>
                  <input type="hidden" name="del_status" value="delete">
              <% elsif @status == 'handled' %>
                  <button id="delete-all-feedback">Phục Hồi Tất Cả</button>
                  <input type="hidden" name="del_status" value="restore">
              <% end %>
            </form>
          </th>
        </tr>
        <% @feedbacks.each do |feedback| %>
            <tr>
              <td><label><input type="checkbox" class="checkbox" value="<%= feedback.id %>"></label></td>
              <td><%= feedback.email %></td>
              <td><%= feedback.content %></td>
              <td><%= feedback.send_day %></td>
              <td>
                <a href="#" class="delete-feedback">
                  <input class="hdnFeedbackID" type="hidden" value="<%= feedback.id %>"/>
                  <% if @status == 'nothandle' %>
                      Xóa
                  <% elsif @status == 'handled' %>
                      Phục hồi
                  <% end %>
                </a>
              </td>
            </tr>
        <% end %>
      </table>
    </div>
    <script type="text/javascript">
        $('#check-all-feedback').click(function () {
            if ($(this).is(':checked')) {
                $('.checkbox').prop('checked', true);
            } else {
                $('.checkbox').prop('checked', false);
            }
        });
        $('#delete-all-feedback').click(function () {
            var form = $('#delete-form');

            var checkedBoxTags = $('.checkbox:checked');
            if (checkedBoxTags.length > 0) {
                for (var i = 0; i < checkedBoxTags.length; i++) {
                    var feedbackID = checkedBoxTags[i].value;
                    var hdnTag = '<input type="hidden" name="feedbackIDs[]" value="' + feedbackID + '"/>';
                    form.append(hdnTag);
                }
            }

            form.submit();
        });
        $('.delete-feedback').click(function () {
            var form = $('#delete-form');
            var deletedFeedbackID = $(this).find('.hdnFeedbackID').val();
            form.append('<input type="hidden" name="feedbackIDs[]" value="' + deletedFeedbackID + '"/>');
            form.submit();
        });
    </script>
    <style>
        #feedback-menu {
            margin-bottom: 30px;
            background-color: #E1EEF4;
            border-radius: 3px;
        }

        #feedback-menu ul li {
            border-radius: 3px;
            cursor: pointer;
            font-size: 14px;
            font-weight: 700;
            line-height: 36px;
        }

        #feedback-menu ul ul {
            display: none;
        }

        #feedback-menu ul li:hover > ul {
            border-radius: 3px;
            display: block;
        }

        #feedback-menu > ul {
            width: 100%;
            list-style: none;
            position: relative;
            display: inline-table;
        }

        #feedback-menu ul:after {
            content: "";
            clear: both;
            display: block;
        }

        #feedback-menu ul li {
            float: left;
        }

        #feedback-menu ul li:hover {
            background: #4b545f;
            background: linear-gradient(top, #4f5964 0%, #5f6975 40%);
            background: -moz-linear-gradient(top, #4f5964 0%, #5f6975 40%);
            background: -webkit-linear-gradient(top, #4f5964 0%, #5f6975 40%);
            box-shadow: 0 0 9px rgba(0, 0, 0, 0.15);
        }

        #feedback-menu ul li:hover a {
            color: #fff;
        }

        #feedback-menu ul li a {
            color: black;
            display: block;
            padding: 20px;
            text-decoration: none;
        }

        #feedback-menu ul ul {
            background: #5f6975;
            padding: 0;
            position: absolute;
            top: 100%;
        }

        #feedback-menu ul ul li {
            float: none;
            border-top: 1px solid #6b727c;
            border-bottom: 1px solid #575f6a;
            position: relative;
        }

        #feedback-menu ul ul li a {
            padding: 15px 40px;
            color: #fff;
        }

        #feedback-menu ul ul li a:hover {
            background: #4b545f;
        }

        #feedback-menu ul ul ul {
            position: absolute;
            left: 100%;
            top: 0;
        }

    </style>
<% end %>


